import datetime

import pymysql, uuid


class TestMysql:
    def __init__(self):
        self.connect = pymysql.connect(host='192.168.177.129', user='root', password='123456', db='scrapy_hospital',
                                       port=3306)
        self.cursor = self.connect.cursor()
        print("数据库连接成功")

    def insertData(self):
        id = self.generateId()
        # date = datetime.date(2021,1,1)
        date = None
        sql = 'INSERT INTO test_insert (c_id,c_name,n_age,d_date) VALUES (%s,%s,%s,%s)'
        self.cursor.execute(sql, (id, "娜美3", 18, None))
        self.connect.commit()
        print("插入数据成功")
        self.cursor.close()
        self.connect.close()

    def generateId(self):
        return str(uuid.uuid1()).replace("-", "")


test = TestMysql()
test.insertData()
